﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_DeletePwd : System.Web.UI.Page,HZ.MBSM.BLL.IPageDescribe
{
    String StrSql, strConditions;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            if(!this.IsPostBack)
            {
                
                Db db = new Db();
                System.Data.IDataReader dr;
                StrSql = "Select Title,ProjectId From Project order by projectid desc";
                dr = db.DataReader(StrSql);
                DLProject.DataSource = dr;
                DLProject.DataTextField = "Title";
                DLProject.DataValueField = "ProjectId";
                DLProject.SelectedIndex = 0;
                DLProject.DataBind();
                dr.Close();
                dr.Dispose();
                db.Close();
                DeleButton();
                showGridView();
            }
            else
            {
                DeleButton();
                showGridView();

            }
           
        }

    }

  
 
         /// <summary>
    /// 查询总共有多少页
    /// </summary>
    /// <returns></returns>
    /// <summary>
    /// 将数据绑定到GridView1
    /// </summary>
    /// <param name="PageIndex">转向第几页</param>
    public void showGridView()
    {

        string _SelectField = "UserCode,CompanyName,ProjectCompanyAttribution.AccountId";
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "ComPany,ProjectCompanyAttribution";                                               //要查询的表明
        dbPage.Key = "ProjectCompanyAttribution.AccountId";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = _SelectField;//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "UserCode";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        this.GridView1.DataSource = dr;
        this.GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    public String fctConditions()
    {
        String _StrTemp,CompanyName,UserCode;
        CompanyName=txtCompanyName.Text;
        UserCode=txtUserCode.Text;
        _StrTemp = " Company.Accountid=ProjectCompanyAttribution.Accountid And ProjectId='" + DLProject.SelectedValue.ToString() + "' And";
        if (CompanyName != "")
        {
            _StrTemp += " CompanyName Like '%" + CompanyName + "%' And";
        }
        if (UserCode != "")
        {
            _StrTemp += " UserCode Like '%" + UserCode + "%' And";
        }
        if (_StrTemp != "")
        {
            _StrTemp = "  " + _StrTemp.Substring(0, _StrTemp.Length - 3);
        }

        return _StrTemp;
    }

    public void DeleButton()
    {
        String AccountId;//投标人ID
        if (Request.Form["delePwd"] == "删除投标报价密码" && Request.Form["txtprice"] != null)
        {
            Db db = new Db();
            string _strProjectId = DLProject.SelectedValue.ToString();
            AccountId = Request.Form["txtprice"].ToString();
            StrSql = "Update ProjectCompanyAttribution Set PricePassword=Null,RetinuePassword=Null Where AccountId in (" + AccountId + ") and ProjectId=" + _strProjectId;
            db.Command(StrSql);
            db.Close();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "ProjectCompanyAttribution", StrSql, "../Magage/DeletePwd.aspx");

            Response.Write("<script>alert('恭喜！！！已经成功删除该企业得竞价报价密码！！！');</script>");

        }
        
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //插入文本框
            e.Row.Cells[2].Text = "<input type=checkbox name='txtprice' value=\"" + SysFun.ToDec(e.Row.Cells[3].Text) + "\" /> ";
        }
        e.Row.Cells[3].Visible = false;
    }
    #region IPageDescribe 成员

    public string Name
    {
        get { return "删除投标报价密码"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "投标人报价密码删除"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
            return _AccountType;
        }
    }

    #endregion
}
